<h1> Relatório: <small>Os nomes dos servicos que foram vendidos, sua quantidade, o total de dinheiro gasto e qual o funcionario que vendeu em uma determinanda data.</small></h1>
<code>SELECT IFNULL(f.nome, 'sem identificação') AS func, 
    COUNT(sc.idservico) AS quant_serv, s.nome AS servico,  
    Concat('R$ ', Replace (Replace (Replace (FORMAT(IFNULL(SUM(sc.preco), 0), 2), '.', '|'), ',', '.'), '|', ',')) AS total
    FROM venda v
    JOIN funcionario f ON f.idfuncionario = v.idfuncionario
    JOIN servicosComprados sc ON v.idvenda = sc.idvenda       
    JOIN servico s ON sc.idservico = s.idservico
    WHERE
    v.data BETWEEN '2014-02-02' AND '2014-12-12'
    GROUP BY f.nome, s.idservico
    ORDER BY f.nome, s.idservico
</code>
<div class="bs-example">
    <br/>
    <div id="rel1">
        <form role="form" action="?s=crelatorios&rel1" method="post" class="form-horizontal">
            <div class="form-group">
                <label class="col-xs-2 col-sm-2 col-md-2 col-lg-2 text-right" for="dtInicio">Data Inicio:</label>
                <div class="col-xs-2 col-sm-2 col-md-2 col-lg-2">
                    <input class="form-control" type="text" id="dtInicio" name="dtInicio" value="<?= $dtini ?>">
                </div>

                <label class="col-xs-2 col-sm-2 col-md-2 col-lg-2 text-right" for="dtFim">Data Fim:</label>
                <div class="col-xs-2 col-sm-2 col-md-2 col-lg-2">
                    <input class="form-control" type="text" id="dtFim" name="dtFim" value="<?= $dtfim ?>">
                </div>
                <div class="col-xs-2 col-sm-2 col-md-2 col-lg-2">
                    <button type="submit">Pesquisar</button>
                </div>
            </div>
        </form>


        <table class="table table-striped table-hover">
            <tr>
                <th>Nome Funcionario</th>
                <th>Nome do serviço</th>
                <th class="col-xs-2 col-sm-2 col-md-2 col-lg-2 text-right">Quantidade</th>
                <th class="col-xs-2 col-sm-2 col-md-2 col-lg-2 text-right">Total R$</th>
            </tr>
            <?php foreach ($result as $ele) { ?>
                <tr>
                    <td><?= $ele['func'] ?></td>
                    <td><?= $ele['servico'] ?></td>
                    <td class="text-right"><?= $ele['quant_serv'] ?></td>
                    <td class="text-right"><?= $ele['total'] ?></td>
                </tr>
            <?php } ?>
        </table>
    </div>
</div>


<script>
    $(function () {
        $("#dtInicio").datepicker({
            duration: "slow",
            changeMonth: true,
            numberOfMonths: 3,
            dateFormat: 'dd/mm/yy',
            onClose: function (selectedDate) {
                $("#dtFim").datepicker("option", "minDate", selectedDate);
            }
        });
        $("#dtFim").datepicker({
//            defaultDate: "+1w",
            duration: "slow",
            changeMonth: true,
            numberOfMonths: 3,
            dateFormat: 'dd/mm/yy',
            onClose: function (selectedDate) {
                $("#dtInicio").datepicker("option", "maxDate", selectedDate);
            }
        });
    });
</script>